import {defineStore} from 'pinia';
import videoApi from "@/api/video";
import sortApi from "@/api/sort";

// 创建仓库
export const useVideoStore = defineStore('videos', {
  state: () => ({
    videosList: [], //会员专区
    videosListVideo:[], // 视频专区
    videosListLive:[],// 直播专区
    videosListOffLine:[]//线下课
  }),
  actions: {
    // 获取视频列表--会员专区
    async getSort(tagIndex: any, token: string, pageSize: number, pageNum: number, data: any) {
      let res
      switch (tagIndex) {
        case 1: {
          res = await sortApi.getIntegrated(token, pageSize, pageNum, data)
          break;
        }
        case 2: {
          res = await sortApi.getSellCountDesc(token, pageSize, pageNum, data)
          break;
        }
        case 3: {
          res = await sortApi.getViewCountDesc(token, pageSize, pageNum, data)

          break;
        }
        case 4: {
          res = await sortApi.getPriceDesc(token, pageSize, pageNum, data)
          break;
        }
        case 5: {
          res = await sortApi.getOnsellTimeDesc(token, pageSize, pageNum, data)
          break;
        }
        case 6:{
          res = await sortApi.getFavorableValueDesc(token, pageSize, pageNum, data)
          break;
        }
        case 99: {
          res = await videoApi.getVideoList(token, pageSize, pageNum, data)
        }
        default: {
          res = await sortApi.getIntegrated(token, pageSize, pageNum, data)
        }
      }
      if(pageNum > 0){
        // @ts-ignore
        this.videosList.push(...res.content)
      }else {
        // @ts-ignore
        this.videosList = res.content
      }
    },
    // 获取视频列表--视频专区
    async getSortVideo(tagIndex: any, token: string, pageSize: number, pageNum: number, data: any) {
      let res
      switch (tagIndex) {
        case 1: {
          res = await sortApi.getIntegratedVideo(token, pageSize, pageNum, data)
          break;
        }
        case 2: {
          res = await sortApi.getSellCountDescVideo(token, pageSize, pageNum, data)
          break;
        }
        case 3: {
          res = await sortApi.getViewCountDescVideo(token, pageSize, pageNum, data)

          break;
        }
        case 4: {
          res = await sortApi.getPriceDescVideo(token, pageSize, pageNum, data)
          break;
        }
        case 5: {
          res = await sortApi.getOnsellTimeDescVideo(token, pageSize, pageNum, data)
          break;
        }
        case 6:{
          res = await sortApi.getFavorableValueDescVideo(token, pageSize, pageNum, data)
          break;
        }
        case 99: {
          res = await videoApi.getVideoList(token, pageSize, pageNum, data)
        }
        default: {
          res = await sortApi.getIntegrated(token, pageSize, pageNum, data)
        }
      }
      if(pageNum > 0){
        // @ts-ignore
        this.videosListVideo.push(...res.content)
      }else {
        // @ts-ignore
        this.videosListVideo = res.content
      }
    },
    // 获取视频列表--直播专区
    async getSortLive(tagIndex: any, token: string, pageSize: number, pageNum: number, data: any) {
      let res
      switch (tagIndex) {
        case 1: {
          res = await sortApi.getIntegratedLive(token, pageSize, pageNum, data)
          break;
        }
        case 2: {
          res = await sortApi.getSellCountDescLive(token, pageSize, pageNum, data)
          break;
        }
        case 3: {
          res = await sortApi.getViewCountDescLive(token, pageSize, pageNum, data)

          break;
        }
        case 4: {
          res = await sortApi.getPriceDescLive(token, pageSize, pageNum, data)
          break;
        }
        case 5: {
          res = await sortApi.getOnsellTimeDescLive(token, pageSize, pageNum, data)
          break;
        }
        case 99: {
          res = await videoApi.getVideoList(token, pageSize, pageNum, data)
        }
        default: {
          res = await sortApi.getIntegrated(token, pageSize, pageNum, data)
        }
      }
      if(pageNum > 0){
        // @ts-ignore
        this.videosListLive.push(...res.content)
      }else {
        // @ts-ignore
        this.videosListLive = res.content
      }
    },
    //线下课
    async getSortOffLine(tagIndex: any, token: string, pageSize: number, pageNum: number, data: any) {
      let res
      switch (tagIndex) {
        case 1: {
          res = await sortApi.getIntegratedOffLine(token, pageSize, pageNum, data)
          break;
        }
        case 2: {
          res = await sortApi.getSellCountDescOffLine(token, pageSize, pageNum, data)
          break;
        }
        case 3: {
          res = await sortApi.getViewCountDescOffLine(token, pageSize, pageNum, data)

          break;
        }
        case 4: {
          res = await sortApi.getPriceDescOffLine(token, pageSize, pageNum, data)
          break;
        }
        case 5: {
          res = await sortApi.getOnsellTimeDescOffLine(token, pageSize, pageNum, data)
          break;
        }
        case 99: {
          res = await videoApi.getVideoList(token, pageSize, pageNum, data)
        }
        default: {
          res = await sortApi.getIntegratedOffLine(token, pageSize, pageNum, data)
        }
      }
      if(pageNum > 0){
        // @ts-ignore
        this.videosListOffLine.push(...res.content)
      }else {
        // @ts-ignore
        this.videosListOffLine = res.content
      }
    },

  },

  getters: {}
})
